'''通过创建索引类,来指明让搜索引擎对那些字段建立索引,也就是可以通过
那些字段的关键字来检索数据'''

from haystack import indexes
from xj_users.models import Article


class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    id = indexes.IntegerField(model_attr='id')
    title = indexes.CharField(model_attr='title')
    content = indexes.CharField(model_attr='content')
    createtime = indexes.DateTimeField(model_attr='createtime')

    def get_model(self):
        return Article

    def index_queryset(self, using=None):
        return self.get_model().objects.all()